Skip to content

fix(parser): preserve regex literals ending in an escaped slash - #740

Merged
Brooooooklyn merged 4 commits into
mainfrom
polish/pr-738
Nov 25, 2026
Merged

Brooooooklyn merged 4 commits into
mainfrom
polish/pr-738

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Supersedes #738 by @nagahara-naoki. Their commit is kept as is, with their authorship, and 3 polish commits go on top. The fork does not allow maintainer edits, so this is a new PR.

The bug

<button (click)="result = path.replace(/^\//, '') // normalize path">

Angular's _commentStart skips the character after a backslash, so the // in /^\// is not a comment. We cut the expression there and failed with Unterminated regular expression. The same thing broke escaped quotes before a comment ('it\'s' // c), in every kind of binding.

Commits

Commit What
fix(parser): preserve regex literals ending in an escaped slash (#738, nagahara-naoki) find_comment_start skips escaped chars like Angular. Event handler_span is the whole value span, as in Angular. The assignment span no longer adds the offset twice.
test(conformance): keep checking event handler spans #738 switched the runner to unparsing event handlers, so a wrong event span would still pass. This goes back to slicing the source, using the handler's own span.
fix(parser): find the end of an interpolation like Angular {{ }} had the same problem: {{ s.replace(/\//g, '').replace(/'/g, '') }} and {{ s.replace(/[/*]/g, '') }} became static text. This is a direct port of _getInterpolationEndIndex + _forEachUnquotedChar.
test(parser): cover escaped quotes and event handler spans Angular's 2 spec cases, a find_comment_start table, and handler spans for on-, [()], bindon- and (@x.done).

Checks

comment search vs Angular's real Parser   1.6M random inputs → 0 differences   (main: ~5,000)
{{ }} end search vs Angular              1.3M random inputs → 0 differences
templates vs ngc 22.3.0                  main 4/30 · #738 26/30 · this PR 30/30
spans (handler + assignment)             equal to Angular on every case checked
output vs main, 1198 files × 4 options   same
conformance                              1430 → 1432 / 1456, ast_spans 55/55
cargo test --all-features                4256 passed

Mutation check for the runner: shifting every event span by 1 fails 6 ast_spans cases now. With the runner from #738 it still passed 55/55.

Not in this PR (older, separate)

  • Microsyntax (*ngFor="…") strips // comments, but Angular doesn't.
  • A comment-only {{ // c }} gives no error, but Angular reports one.
  • A regex nested inside a call is not hoisted to a constant the way ngc does it.
  • The conformance extractor drops AbsoluteSourceSpan numbers and gets 0 assertions from the parseInterpolation specs.

🤖 Generated with Claude Code

nagahara-naoki and others added 4 commits November 25, 2026 22:14
Cut the expected text out of the source by the parsed handler's own span
instead of by handler_span. handler_span is now the whole attribute value
(comment included, like Angular), while the spec expects the parsed
expression. Unparsing the handler instead would pass even if every event
span were wrong.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
find_interpolation_end had three rules Angular's _getInterpolationEndIndex
does not: `//` was a comment only after an even number of backslashes, a
`//` comment ended at a newline, and `/* */` hid `}}`. When no end was
found the whole `{{ ... }}` became static text, e.g.
`{{ s.replace(/\//g, '').replace(/'/g, '') }}` and
`{{ s.replace(/[/*]/g, '') }}`. Port Angular's loop
(_getInterpolationEndIndex + _forEachUnquotedChar) directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port Angular's two spec cases (a regex ending in an escaped slash, escaped
quotes before a comment), add a find_comment_start table, and check that
handler_span keeps the trailing comment on on-, [()], bindon- and legacy
animation events, as Angular's handlerSpan does. Update the
find_comment_start doc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T14:36:43.493051Z 08f62f0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 08f62f0b3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn enabled auto-merge (squash) November 25, 2026 15:01
@Brooooooklyn
Brooooooklyn merged commit fa57eed into main Nov 25, 2026
16 of 17 checks passed
@Brooooooklyn
Brooooooklyn deleted the polish/pr-738 branch November 25, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants